package com.glodon.paas.activity.util;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.glodon.paas.activity.api.bean.ActivityDefinition;
import com.glodon.paas.activity.dao.domain.ActivityDefinitionEntity;

public class ActivityDefinitionHelp {

    static String[] ignoreProperties = new String[] { "defaultReceiver", "noticeChannel" };

    public static ActivityDefinitionEntity toActivityDefinitionEntity(ActivityDefinition source) {
        if (source == null) {
            return null;
        }
        ActivityDefinitionEntity target = new ActivityDefinitionEntity();
        BeanUtils.copyProperties(source, target);
        // defaultReceiver
        target.setDefaultReceiver(NumberUtil.array2long(source.getDefaultReceivers()));
        // defaultReceiver
        target.setNoticeChannel(NumberUtil.array2long(source.getNoticeChannels()));
        return target;
    }

    public static ActivityDefinition toActivityDefinition(ActivityDefinitionEntity source) {
        if (source == null) {
            return null;
        }
        ActivityDefinition target = new ActivityDefinition();
        BeanUtils.copyProperties(source, target);
        // defaultReceiver
        target.setDefaultReceivers(NumberUtil.long2Array(source.getDefaultReceiver()));
        // defaultReceiver
        target.setNoticeChannels(NumberUtil.long2Array(source.getNoticeChannel()));
        return target;
    }

    public static List<ActivityDefinition> toActivityDefinition(List<ActivityDefinitionEntity> source) {
        if (source == null) {
            return null;
        }
        List<ActivityDefinition> target = new ArrayList<ActivityDefinition>();
        for (ActivityDefinitionEntity item : source) {
            target.add(toActivityDefinition(item));
        }
        return target;
    }
}
